'use strict';

const BaseService = require('./base');

class OrderItemService extends BaseService {
  constructor(ctx) {
    super(ctx, 'OrderItem');
  }
  
  // 重写create方法，支持事务
  async create(data, transaction = null) {
    const options = {};
    if (transaction) options.transaction = transaction;
    
    return this.ctx.model.OrderItem.create(data, options);
  }
  
  // 根据订单ID获取订单物品列表
  async getItemsByOrderId(orderId) {
    return this.ctx.model.OrderItem.findAll({
      where: { order_id: orderId },
      include: [{
        model: this.ctx.model.Item,
        as: 'item',
        attributes: ['id', 'item_name', 'item_code']
      }]
    });
  }
}

module.exports = OrderItemService;
